package org.example.c2;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * @author liu-rui
 * @date 2020/6/3 下午5:38
 * @description
 * @since
 */
class MyUnSafe {
    static Unsafe unsafe;

    static {
        final Field field;
        try {
            field = Unsafe.class.getDeclaredField("theUnsafe");
            field.setAccessible(true);
            unsafe = (Unsafe) field.get(null);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    public static Unsafe getUnsafe() {
        return unsafe;
    }
}
